<script>
  import config from './config'
  import store from '@/store'
  import { getToken } from '@/utils/auth'

  export default {
    onLaunch: function() {
      this.initApp()
    },
    methods: {
      // 初始化应用
      initApp() {
        // 初始化应用配置
        this.initConfig()
		// console.log("sdsdsdsdsd");
		// this.getUrlCode()
        // 检查用户登录状态
        //#ifdef H5
        this.checkLogin()
        //#endif
      },
      initConfig() {
        this.globalData.config = config
      },
      checkLogin() {
		console.log('location.search:',location);
		console.log("getToken", getToken())
        if (!getToken()) {
			// console.log('getToken');
			// console.log("location.hash", location.hash)
			
			if(location.hash.includes('/wechat/callback')){
				// console.log("location.hash", location.hash.split('?')[1])
				const pageUrl = '/pages'+location.hash.substring(1);
				// console.log("reLaunch", pageUrl)
			}
			if('/wechat/callback' == location.pathname) {
				// console.log('1');
				// console.log('reLaunch:',location.pathname);
				this.$tab.reLaunch('/pages/wechat-callback'+location.search)
			} else if(location.hash.includes('/wechat/callback')){
				// console.log('2');
				const pageUrl = '/pages/wechat-callback'+location.search;
				// console.log('try to ', pageUrl);
				// 
				this.$tab.reLaunch(pageUrl)
			}else{
				// console.log('3');
				// console.log('reLaunch: login');
				this.$tab.reLaunch('/pages/login')
			}
        } else{
			// console.log('4');
			this.$tab.reLaunch('/pages/index')
		}
      }
    }
  }
</script>

<style lang="scss">
  @import '@/static/scss/index.scss'
</style>
